package com.whately.core.database.common.srv;

import com.whately.core.database.common.dal.mapper.CommonSequenceMapperExt;
import com.whately.core.database.common.dal.model.CommonSequence;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 开启事务
 */
@Service
@Slf4j
public class CoreSequenceTxFactory {

    @Resource
    CommonSequenceMapperExt sysSequenceMapperExt;

    /**
     * 事务不能跨库调用，否则会失败
     * 即sequence一定是在主业务库上
     */
    public CommonSequence updateAndGetIncreasedSequenceByCodeOpenTx(String sequenceCode) {
        CommonSequence sysSequence = sysSequenceMapperExt.selectOneBySequenceCode(sequenceCode);
        sysSequenceMapperExt.updateAndGetIncreasedSequenceByCode(sysSequence);
        return sysSequence;
    }
}
